import { get_site_config } from '~/api';
export const useSiteConfigStore = defineStore(
  'site_config',
  () => {
    const site_name = ref('');
    const short_name = ref('');
    const mobile = ref('');
    const adress = ref('');
    const mail = ref('');
    const beian = ref('');
    const copyright = ref('');
    const qrcode = ref('');
    const company_name = ref('');
    const photo = ref('');
    const carousel = ref<string[]>([]);

    async function set_config() {
      let data = await get_site_config();
      if (data) {
        site_name.value = data.site_name;
        short_name.value = data.short_name;
        mobile.value = data.mobile;
        adress.value = data.adress;
        mail.value = data.mail;
        beian.value = data.beian;
        copyright.value = data.copyright;
        qrcode.value = data.qrcode;
        company_name.value = data.company_name;
        photo.value = data.photo;
        carousel.value = data.carousel;
        // console.log('set_config', data);
      }
      return data;
    }
    return {
      site_name,
      short_name,
      mobile,
      adress,
      mail,
      beian,
      copyright,
      qrcode,
      company_name,
      photo,
      carousel,
      set_config,
    };
  },
  {
    persist: true,
  }
);
